#include<iostream>
#include<cstdio>
using namespace std;
int A[1000],n;
void printf(){
	for(int i=0;i<n;i++)cout<<A[i]<<" ";
	cout<<"\n";
}
void dfs(int cur){
	if(cur==n)printf();
	else for(int i=1;i<=n;i++){
		int ok=1;
		for(int j=0;j<cur;j++)
			if(A[j]==i)ok=0;
		if(ok){
			A[cur]=i;
			dfs(cur+1);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	freopen("test.txt","w",stdout);
	cin>>n;
	dfs(0);
	return 0;
}
